home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / contrib / kostas / noweb-mode.el < prev    next >
Lisp/Scheme  |  1995-02-24  |  4KB  |  121 lines

  1. ;; noweb mode. Relies on tex-support.el.
  2.  
  3. ;; We assume that the .nw file contains one of the following lines at the top
  4. ;;    % -*-lang : math-*-
  5. ;;    % -*-lang : oot-*-
  6. ;;    % -*-lang : icon-*-
  7.  
  8.  
  9. (defun noweb-mode ()
  10.   "noweb mode for Lucid Emacs"
  11.   (interactive)
  12.   (setq major-mode 'noweb-mode)
  13.   ; If the file contains a first line like the above, the variable ``lang'' is defined.
  14.   (make-local-variable 'lang)
  15.   (if (equal lang nil)
  16.       (setq mode-name "noweb")
  17.       (setq mode-name (concat (capitalize (prin1-to-string lang)) "-noweb"))
  18.       )
  19.  
  20.   ; nwhome is defined in .emacs.
  21.   (defconst nwlib (concat nwhome "lib/"))
  22.   (defconst nwbin (concat nwhome "bin/"))
  23.   ; Weave and tangle commands.
  24.   (defconst weave (concat nwbin "noweave "))
  25.   (defconst tangle (concat nwbin "notangle -L'#line %-1L \"%F\"%N' "))
  26.   (defconst tangle-nl (concat nwbin "notangle ")) ; With no "line" directives.
  27.   ; Suffixes for tangle output files depend on the buffer-local variable lang.
  28.   (defconst t-suffixes '((math . ".m") (oot . ".t") (icon . ".icn")))
  29.   ; Suffixes for executable files.
  30.   (defconst x-suffixes '((math . ".m") (oot . "") (icon . "")))
  31.  
  32.   (defun nw-make (what)
  33.     (interactive)
  34.     (let* (
  35.         ; The file name.
  36.         (file-name (file-name-nondirectory buffer-file-name))
  37.             ; The base name of the file (without the ".nw" suffix).
  38.         (base-name (substring file-name 0 -3))
  39.             ; t-suff is the suffix of the file where tangle's output should go.
  40.         (t-suff (cdr (assoc lang t-suffixes)))
  41.         ; x-suff is the suffix of the executable.
  42.         (x-suff (cdr (assoc lang x-suffixes)))
  43.             ; The string form of lang.
  44.         (language (prin1-to-string lang))
  45.         ; filter is the full path name to the filter.
  46.         (filter (concat nwlib language ".filter"))
  47.           )
  48.        ; Now we use the ``make-file'' command provided by tex-support.el to do what
  49.        ; we want. A little strange, but it works much better than using compile.el!!
  50.        ; Note: the following ``cond'' defines the arguments to make-file.
  51.        (cond
  52.       ((or (equal what "dvi") (equal what "tex"))
  53.        (setq tex-command (concat "make " base-name "." what)))
  54.       ((equal what "x")
  55.        (setq tex-command (concat "make " base-name x-suff)))
  56.       ((equal what "weave")
  57.        (setq tex-command 
  58.          (if (equal lang nil)
  59.              (concat weave " -index " file-name " > " base-name ".tex")
  60.              (concat weave "-autodefs " language " -index -filter " filter " "
  61.                  file-name " > " base-name ".tex")
  62.          )
  63.            ))
  64.       ((equal what "tangle")
  65.        (setq tex-command (concat (if (equal lang 'math) tangle-nl tangle) file-name
  66.                      " > " base-name t-suff)))
  67.       ((equal what "?")
  68.        (let ((insert-default-directory nil))
  69.          (setq tex-command
  70.            (concat "make " (file-name-nondirectory
  71.                     (read-file-name "Make (file name): ")))
  72.          )
  73.        ))
  74.        )
  75.        (make-file)
  76.      )
  77.   )
  78.  
  79.  
  80.   (defconst noweb-menu
  81.     '("noweb"
  82.       ["Make tex"  (nw-make "tex")  t]
  83.       ["Make dvi"  (nw-make "dvi")  t]
  84.       ["Make x"    (nw-make "x")    t]
  85.       "-----"
  86.       ["Weave"     (nw-make "weave") t]
  87.       ["Tangle"    (nw-make "tangle") t]
  88.       ("More ..."  ["Make ..."  (nw-make "?")    t]
  89.            "-----"
  90.            ["View"      (nw-display "view")  t]
  91.            ["Print"     (nw-display "print") t]
  92.            )
  93.      )
  94.   )
  95.  
  96.  
  97.   (defun install-noweb-menu ()
  98.     "Install a buffer-local noweb menu."
  99.     (interactive)
  100.     (progn
  101.       (set-buffer-menubar (copy-sequence my-default-menubar))
  102.       (add-menu nil "noweb" (cdr noweb-menu))
  103.     )
  104.   )
  105.  
  106.  
  107.   (defun nw-display (how)
  108.     "A modification of \"tex-print\" in tex-support.el"
  109.     (interactive)
  110.     (tex-send-command 
  111.      (cond ((equal how "view") 
  112.         tex-dvi-view-command)
  113.        ((equal how "print")
  114.         tex-dvi-print-command))
  115.      (concat (substring (file-name-nondirectory buffer-file-name) 0 -3) ".dvi") t)
  116.   )
  117.  
  118.   (run-hooks 'noweb-mode-hook)  
  119.  
  120. )
  121.